//
//  UIBarButtonItem+PGExtend.m
//  youqu
//
//  Created by 彭鹏 on 16/9/4.
//  Copyright © 2016年 pengpeng. All rights reserved.
//

#import "UIBarButtonItem+PGExtend.h"

@implementation UIBarButtonItem (PGExtend)

//带有高亮的button
+ (instancetype)barButtonItemWithImageNamed:(NSString *)imageNormal imageHighlighted:(NSString *)imageHighlighted target:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageNormal] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageHighlighted] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    UIView *view = [[UIView alloc] initWithFrame:btn.bounds];
    [view addSubview:btn];
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchDown];
    
    return [[UIBarButtonItem alloc] initWithCustomView:view];
    
}

//带有选择的button
+ (instancetype)barButtonItemWithImageNamed:(NSString *)imageNormal imageSelected:(NSString *)imageSelected target:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageNormal] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageSelected] forState:UIControlStateSelected];
    [btn sizeToFit];
    UIView *view = [[UIView alloc] initWithFrame:btn.bounds];
    [view addSubview:btn];
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchDown];
    
    return [[UIBarButtonItem alloc] initWithCustomView:view];
    
}

@end
